<?php
class FindNoIndividu{
	private $no_individu;
	private $db;
    private $exclude_id;
	
	function FindNoIndividu($db=NULL, $no_individu=NULL){
		$this->no_individu 	 = $no_individu;
		$this->db 			 = $db;
	}	
    
    public function exclude($id){
        $this->exclude_id = $id;
    }
	
    private function getNoIndividuById($id){
        $q = "SELECT no_individu FROM caramel_operational.penanaman WHERE id='$id'";
        return $this->db->get_var($q);
    }
    
	function response(){           
        // get no individu
        $no_individu = $this->getNoIndividuById($this->exclude_id);
        if( $this->no_individu == $no_individu ){
            echo "true";
            return;
        }
        
        $q = "SELECT COUNT(*) FROM `caramel_managerial`.`pancang` WHERE `no_individu`='".$this->no_individu."'";
        $r = $this->db->get_var($q);
        
        if( $r > 0 ){
            // cari di biodata... no individu tidak boleh ada yang sama dengan yang lalu2...
            $q = "SELECT COUNT(*) FROM `caramel_managerial`.`biodata_tanaman` WHERE `no_individu`='".$this->no_individu."'";
            $r = $this->db->get_var($q);
            
            if( $r > 0 )
                echo "false";
            else
                echo "true";
        }	
        else
            echo "true";
        
	}	
}

$no_individu	= $_GET['no_individu'];

$ref = $_SERVER['HTTP_REFERER'];
$pos = strpos($ref, 'id=')+3;
$id  = substr($ref, $pos);

// load database class handler
include_once '../config/db_config.php';
include '../library/ezsql/shared/ez_sql_core.php';
include '../library/ezsql/mysql/ez_sql_mysql.php';

// database handler
$db = new ezSQL_mysql($dbUser, $dbPass, $dbName, $dbHost);
$finder = new FindNoIndividu($db, $no_individu);
$finder->exclude($id);
$finder->response();
?>